package com.topsun.posclient.system.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.topsun.posclient.common.service.impl.BaseServiceImpl;
import com.topsun.posclient.system.dao.OperatorLocalDao;
import com.topsun.posclient.system.entity.Operator;
import com.topsun.posclient.system.entity.OperatorDTO;
import com.topsun.posclient.system.service.IOperatorService;

@Service("operatorService")
public class OperatorServiceImpl extends BaseServiceImpl implements IOperatorService {
	
	@Autowired
	private OperatorLocalDao operatorLocalDao;

	@Override
	public Operator getOperator(String name, String password)
			throws Exception {
		Operator loginOpr = null;
		OperatorDTO operatorDTO = operatorLocalDao.getOperatorData();
		if(null == operatorDTO){
			return null;
		}
		List<Operator> operators = operatorDTO.getOperatorList();
		for(Operator o : operators){
			if(o.getName().equals(name) && o.getPassword().equals(password)){
				loginOpr = o;
			}
		}
		return loginOpr;
	}

}
